package sort;

import java.util.Arrays;
import java.util.Random;

/**插入排序*/
public class InsertSort {
    public static void main(String[] args) {
        int [] arr = new int[100];
        Random random = new Random();
        for (int i = 0; i < arr.length; i++) {
            arr[i]= random.nextInt(100);
        }
        long s1 = System.currentTimeMillis();
        for (int i = 1; i <arr.length ; i++) {
            int j =i;
            while (j>0){
                if(arr[j]<arr[j-1]){
                    int temp = arr[j];
                    arr[j] = arr[j-1];
                    arr[j-1] = temp;
                    j--;
                }else {
                    break;
                }
            }
        }
        long e1 = System.currentTimeMillis();
        System.out.println(e1-s1);
        System.out.println(Arrays.toString(arr));
        System.out.println("--------------");
    }
}
